babl: make pixel-count instrumentation opt-in
authorØyvind Kolås <pippin@gimp.org>
Wed, 17 Jan 2018 02:46:59 +0000 (03:46 +0100)
committerØyvind Kolås <pippin@gimp.org>
Wed, 17 Jan 2018 02:49:32 +0000 (03:49 +0100)
Checking if an integer is 0/1 is lower overhead than incrementing a long stored
kt a memory location. As a side effect, the entries in
~/.cache/babl/babl-fishes will not be sorted by most used to least used unless
the BABL_INSTRUMENT environment variable is set to a value.

babl/babl-fish-path.c
babl/babl-internal.h

index 867cb8d3d926223ca535c8b00a0be5cf258ec460..eb10fe9fcf597a0885c9ccf7e435534ba2b8d6da 100644 (file)
@@ -99,6 +99,7 @@ _babl_fish_create_name (char       *buf,
 static int max_path_length (void);
 
 static int debug_conversions = 0;
+int _babl_instrument = 0;
 
 double _babl_legal_error (void)
 {
@@ -120,6 +121,12 @@ double _babl_legal_error (void)
   else
     debug_conversions = 0;
 
+  env = getenv ("BABL_INSTRUMENT");
+  if (env && env[0] != '\0')
+    _babl_instrument = 1;
+  else
+    _babl_instrument = 0;
+
   return error;
 }
 
@@ -732,8 +739,9 @@ _babl_process (const Babl *cbabl,
                long        n)
 {
   Babl *babl = (void*)cbabl;
-  babl->fish.pixels += n;
   babl->fish.dispatch (babl, source, destination, n, *babl->fish.data);
+  if (_babl_instrument)
+    babl->fish.pixels += n;
   return n;
 }
 
@@ -765,7 +773,8 @@ babl_process_rows (const Babl *fish,
   if (n <= 0)
     return 0;
 
-  babl->fish.pixels += n * rows;
+  if (_babl_instrument)
+    babl->fish.pixels += n * rows;
   for (row = 0; row < rows; row++)
     {
       babl->fish.dispatch (babl, (void*)src, (void*)dst, n, *babl->fish.data);
@@ -996,7 +1005,7 @@ get_path_instrumentation (FishPathInstrumentation *fpi,
   process_conversion_path (path, fpi->source, source_bpp, fpi->destination,
                            dest_bpp, fpi->num_test_pixels);
   ticks_end = babl_ticks ();
-  *path_cost = ticks_end - ticks_start;
+  *path_cost = (ticks_end - ticks_start);
 
   /* transform the reference and the actual destination buffers to RGBA
    * for comparison with each other
index ff837958d7106e183d9a62372ddcb5b4b9ba1a15..415bc5ed5a3955f813098851efa3ce3fc5aae939 100644 (file)
@@ -483,6 +483,7 @@ void babl_space_to_xyz   (const Babl *space, const double *rgb, double *xyz);
  */
 void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb);
 
+extern int _babl_instrument;
 
 static inline void
 babl_conversion_process (const Babl *babl,
@@ -491,7 +492,8 @@ babl_conversion_process (const Babl *babl,
                          long        n)
 {
   BablConversion *conversion = (BablConversion *) babl;
-  conversion->pixels += n;
+  if (_babl_instrument)
+    conversion->pixels += n;
   conversion->dispatch (babl, source, destination, n, conversion->data);
 }